import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:part_time_job_pro/common/index.dart';

import 'logic.dart';

class ProxyPage extends StatelessWidget {
  ProxyPage({Key? key}) : super(key: key);

  //路由地址
  static const String routeName = "/proxy";
  final logic = Get.find<ProxyLogic>();
  final state = Get.find<ProxyLogic>().state;

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ProxyLogic>(builder: (logic) {
      return Scaffold(
          backgroundColor: AppColor.norWhite01Color,
          appBar: AppBar(
            backgroundColor: AppColor.norWhite01Color,
            leading: InkWell(
                onTap: () {
                  Get.back();
                },
                child: Container(
                  padding: EdgeInsets.all(10.r),
                  child: Image.asset(AssetsImages.appBarBack),
                )),
            elevation: 0,
            title: const Text(
              "代招服务",
              style: AppTheme.appBarStyle,
            ),
          ),
          body: SingleChildScrollView(
              child: Container(
            color: AppColor.norWhite01Color,
            padding: EdgeInsets.symmetric(vertical: 10.r, horizontal: 20.r),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                buildCountrySelect(context),
                buildCompanyName(),
                buildOfferCount(),
                buildJobSalary(),
                buildContactPerson(),
                buildContactMobile(),
                buildOfferDesc(),
                buildSubmitButton()
              ],
            ),
          )));
    });
  }

  //地区选择
  Widget buildCountrySelect(BuildContext context) {
    return Container(
        padding: EdgeInsets.only(top: 10.r),
        color: AppColor.norWhite01Color,
        width: 1.sw,
        child: Column(
          children: [
            Container(
              //padding: EdgeInsets.symmetric(vertical: 2.r, horizontal: 15.r),
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom:
                      BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: Row(children: [
                Container(
                  alignment: Alignment.centerLeft,
                  width: 60.r,
                  child: Text("所属地区",
                      style: TextStyle(
                        color: AppColor.norGray03Color,
                        fontSize: 14.sp,
                      )),
                ),
                Expanded(
                    child: InkWell(
                        onTap: () {
                          logic.showCitySelector(context);
                        },
                        child: Container(
                          padding: EdgeInsets.symmetric(vertical: 10.r),
                          margin: EdgeInsets.only(left: 15.r),
                          child: Text(
                            state.countryText == "" ? "请选择" : state.countryText,
                            style: TextStyle(
                                fontSize: 14.sp,
                                color: state.countryText == ""
                                    ? AppColor.norGrayColor
                                    : AppColor.norBlackColors),
                          ),
                        )))
              ]),
            )
          ],
        ));
  }

  //企业名称
  Widget buildCompanyName() {
    return Container(
        padding: EdgeInsets.only(top: 10.r),
        color: AppColor.norWhite01Color,
        width: 1.sw,
        child: Column(
          children: [
            Container(
              //padding: EdgeInsets.symmetric(vertical: 2.r, horizontal: 15.r),
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom:
                      BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: Row(children: [
                Container(
                  alignment: Alignment.centerLeft,
                  width: 60.r,
                  child: Text("企业名称",
                      style: TextStyle(
                        color: AppColor.norGray03Color,
                        fontSize: 14.sp,
                      )),
                ),
                Expanded(
                    child: Container(
                  margin: EdgeInsets.only(left: 15.r),
                  child: TextField(
                    focusNode: logic.companyFocusNode,
                    keyboardType: TextInputType.text,
                    keyboardAppearance: Brightness.light,
                    autofocus: true,
                    showCursor: true,
                    cursorHeight: 18.sp,
                    onChanged: (text) {
                      logic.updateCompanyName(text);
                    },
                    cursorColor: AppColor.norYellow04Colors,
                    controller: logic.companyTextEditController,
                    decoration: InputDecoration(
                        hintText: "请输入企业名称/机构名称",
                        border: InputBorder.none,
                        suffixIcon: state.companyName.isNotEmpty &&
                                logic.companyFocusNode.hasFocus
                            ? IconButton(
                                color: AppColor.norGrayColor,
                                onPressed: () {
                                  logic.clearCompanyName();
                                },
                                icon: const Icon(Icons.cancel))
                            : SizedBox(
                                width: 0.r,
                              ),
                        hintStyle: TextStyle(
                          color: AppColor.norGrayColor,
                          fontSize: 14.sp,
                        )),
                    style: TextStyle(
                        fontSize: 14.sp, color: AppColor.norBlackColors),
                  ),
                ))
              ]),
            )
          ],
        ));
  }

  //招聘人数
  Widget buildOfferCount() {
    return Container(
        padding: EdgeInsets.only(top: 5.r),
        color: AppColor.norWhite01Color,
        width: 1.sw,
        child: Column(
          children: [
            Container(
              //padding: EdgeInsets.symmetric(vertical: 2.r, horizontal: 15.r),
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom:
                      BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: Row(children: [
                Container(
                  alignment: Alignment.centerLeft,
                  width: 60.r,
                  child: Text("招聘人数",
                      style: TextStyle(
                        color: AppColor.norGray03Color,
                        fontSize: 14.sp,
                      )),
                ),
                Expanded(
                    child: Container(
                  margin: EdgeInsets.only(left: 15.r),
                  child: TextField(
                    focusNode: logic.offerCountFocusNode,
                    autofocus: true,
                    showCursor: true,
                    keyboardType: TextInputType.number,
                    cursorHeight: 18.sp,
                    onChanged: (text) {
                      logic.updateOfferCount(text);
                    },
                    cursorColor: AppColor.norYellow04Colors,
                    controller: logic.offerCountTextEditController,
                    decoration: InputDecoration(
                        hintText: "请输入招聘人数",
                        border: InputBorder.none,
                        suffixIcon: state.offerCount.isNotEmpty &&
                                logic.offerCountFocusNode.hasFocus
                            ? IconButton(
                                color: AppColor.norGrayColor,
                                onPressed: () {
                                  logic.clearOfferCount();
                                },
                                icon: const Icon(Icons.cancel))
                            : SizedBox(
                                width: 0.r,
                              ),
                        hintStyle: TextStyle(
                          color: AppColor.norGrayColor,
                          fontSize: 14.sp,
                        )),
                    style: TextStyle(
                        fontSize: 14.sp, color: AppColor.norBlackColors),
                  ),
                ))
              ]),
            )
          ],
        ));
  }

  //薪资
  Widget buildJobSalary() {
    return Container(
        padding: EdgeInsets.only(top: 5.r),
        color: AppColor.norWhite01Color,
        width: 1.sw,
        child: Column(
          children: [
            Container(
              //padding: EdgeInsets.symmetric(vertical: 2.r, horizontal: 15.r),
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom:
                      BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: Row(children: [
                Container(
                  alignment: Alignment.centerLeft,
                  width: 60.r,
                  child: Text("工作薪资",
                      style: TextStyle(
                        color: AppColor.norGray03Color,
                        fontSize: 14.sp,
                      )),
                ),
                Expanded(
                    child: Container(
                  margin: EdgeInsets.only(left: 15.r),
                  child: TextField(
                    focusNode: logic.jobSalaryFocusNode,
                    autofocus: true,
                    showCursor: true,
                    keyboardType: TextInputType.number,
                    cursorHeight: 18.sp,
                    onChanged: (text) {
                      logic.updateJobSalary(text);
                    },
                    cursorColor: AppColor.norYellow04Colors,
                    controller: logic.jobSalaryTextEditController,
                    decoration: InputDecoration(
                        hintText: "请输入工作薪资",
                        border: InputBorder.none,
                        suffixIcon: state.jobSalary.isNotEmpty &&
                                logic.jobSalaryFocusNode.hasFocus
                            ? IconButton(
                                color: AppColor.norGrayColor,
                                onPressed: () {
                                  logic.clearJobSalary();
                                },
                                icon: const Icon(Icons.cancel))
                            : SizedBox(
                                width: 0.r,
                              ),
                        hintStyle: TextStyle(
                          color: AppColor.norGrayColor,
                          fontSize: 14.sp,
                        )),
                    style: TextStyle(
                        fontSize: 14.sp, color: AppColor.norBlackColors),
                  ),
                ))
              ]),
            )
          ],
        ));
  }

  //联系人
  Widget buildContactPerson() {
    return Container(
        padding: EdgeInsets.only(top: 5.r),
        color: AppColor.norWhite01Color,
        width: 1.sw,
        child: Column(
          children: [
            Container(
              //padding: EdgeInsets.symmetric(vertical: 2.r, horizontal: 15.r),
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom:
                      BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: Row(children: [
                Container(
                  alignment: Alignment.centerLeft,
                  width: 60.r,
                  child: Text("联系人",
                      style: TextStyle(
                        color: AppColor.norGray03Color,
                        fontSize: 14.sp,
                      )),
                ),
                Expanded(
                    child: Container(
                  margin: EdgeInsets.only(left: 15.r),
                  child: TextField(
                    focusNode: logic.contactFocusNode,
                    autofocus: true,
                    showCursor: true,
                    cursorHeight: 18.sp,
                    onChanged: (text) {
                      logic.updateContactName(text);
                    },
                    cursorColor: AppColor.norYellow04Colors,
                    controller: logic.contactTextEditController,
                    decoration: InputDecoration(
                        hintText: "请输入联系人称呼",
                        border: InputBorder.none,
                        suffixIcon: state.contactName.isNotEmpty &&
                                logic.contactFocusNode.hasFocus
                            ? IconButton(
                                color: AppColor.norGrayColor,
                                onPressed: () {
                                  logic.clearContactName();
                                },
                                icon: const Icon(Icons.cancel))
                            : SizedBox(
                                width: 0.r,
                              ),
                        hintStyle: TextStyle(
                          color: AppColor.norGrayColor,
                          fontSize: 14.sp,
                        )),
                    style: TextStyle(
                        fontSize: 14.sp, color: AppColor.norBlackColors),
                  ),
                ))
              ]),
            )
          ],
        ));
  }

  //联系电话
  Widget buildContactMobile() {
    return Container(
        padding: EdgeInsets.only(top: 5.r),
        color: AppColor.norWhite01Color,
        width: 1.sw,
        child: Column(
          children: [
            Container(
              //padding: EdgeInsets.symmetric(vertical: 2.r, horizontal: 15.r),
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom:
                      BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: Row(children: [
                Container(
                  alignment: Alignment.centerLeft,
                  width: 60.r,
                  child: Text("联系电话",
                      style: TextStyle(
                        color: AppColor.norGray03Color,
                        fontSize: 14.sp,
                      )),
                ),
                Expanded(
                    child: Container(
                  margin: EdgeInsets.only(left: 15.r),
                  child: TextField(
                    focusNode: logic.mobileFocusNode,
                    autofocus: true,
                    showCursor: true,
                    cursorHeight: 18.sp,
                    onChanged: (text) {
                      logic.updateTel(text);
                    },
                    keyboardType: TextInputType.phone,
                    cursorColor: AppColor.norYellow04Colors,
                    controller: logic.mobileTextEditController,
                    decoration: InputDecoration(
                        hintText: "请输入联系人电话",
                        border: InputBorder.none,
                        suffixIcon: state.mobileText.isNotEmpty &&
                                logic.mobileFocusNode.hasFocus
                            ? IconButton(
                                color: AppColor.norGrayColor,
                                onPressed: () {
                                  logic.clearTel();
                                },
                                icon: const Icon(Icons.cancel))
                            : SizedBox(
                                width: 0.r,
                              ),
                        hintStyle: TextStyle(
                          color: AppColor.norGrayColor,
                          fontSize: 14.sp,
                        )),
                    style: TextStyle(
                        fontSize: 14.sp, color: AppColor.norBlackColors),
                  ),
                ))
              ]),
            )
          ],
        ));
  }

  //招聘要求
  Widget buildOfferDesc() {
    return Container(
        padding: EdgeInsets.only(top: 5.r),
        color: AppColor.norWhite01Color,
        width: 1.sw,
        child: Column(
          children: [
            Container(
              //padding: EdgeInsets.symmetric(vertical: 2.r, horizontal: 15.r),
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom:
                      BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      padding: EdgeInsets.only(top: 10.r),
                      alignment: Alignment.centerLeft,
                      width: 60.r,
                      child: Text("招聘要求",
                          style: TextStyle(
                            color: AppColor.norGray03Color,
                            fontSize: 14.sp,
                          )),
                    ),
                    Expanded(
                        child: Container(
                      margin: EdgeInsets.only(left: 15.r),
                      child: TextField(
                        focusNode: logic.jobDescFocusNode,
                        autofocus: true,
                        showCursor: true,
                        maxLines: 6,
                        cursorHeight: 18.sp,
                        onChanged: (text) {
                          logic.updateJobDesc(text);
                        },
                        keyboardType: TextInputType.phone,
                        cursorColor: AppColor.norYellow04Colors,
                        controller: logic.jobDescTextEditController,
                        decoration: InputDecoration(
                            hintText: "请输入招聘要求",
                            border: InputBorder.none,
                            suffixIcon: state.jobDesc.isNotEmpty &&
                                    logic.jobDescFocusNode.hasFocus
                                ? IconButton(
                                    color: AppColor.norGrayColor,
                                    onPressed: () {
                                      logic.clearJobDesc();
                                    },
                                    icon: const Icon(Icons.cancel))
                                : SizedBox(
                                    width: 0.r,
                                  ),
                            hintStyle: TextStyle(
                              color: AppColor.norGrayColor,
                              fontSize: 14.sp,
                            )),
                        style: TextStyle(
                            fontSize: 14.sp, color: AppColor.norBlackColors),
                      ),
                    ))
                  ]),
            )
          ],
        ));
  }

  //提交按钮
  Widget buildSubmitButton() {
    return GestureDetector(
        onTap: () {
          logic.submitOfferProxy();
        },
        child: Container(
          width: 1.sw,
          alignment: Alignment.center,
          margin: EdgeInsets.only(top: 15.r, bottom: 0),
          padding: EdgeInsets.symmetric(vertical: 10.r),
          decoration: BoxDecoration(
              color: AppColor.norYellow04Colors,
              borderRadius: BorderRadius.circular(6)),
          child: Text("提交",
              style:
                  TextStyle(color: AppColor.norWhite01Color, fontSize: 20.sp)),
        ));
  }
}
